package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import ru.gosoplata.model.TmpModel;
	
	/**
	 * ...
	 * @author a.orleansky
	 */
	public class TerminalClock extends Sprite 
	{
		private var time_field:TextField;
		private var date_field:TextField;
		private var months:Array = new Array("января",
											 "февраля",
											 "марта",
											 "апреля",
											 "мая",
											 "июня",
											 "июля",
											 "августа",
											 "сентября",
											 "октября",
											 "ноября",
											 "декабря");
		public function TerminalClock() 
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		public function init(e:Event=null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			createTextFields();
			showDate();
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(e:Event):void 
		{
			showDate();
		}
		
		private function createTextFields():void {
			time_field = new TextField();
			time_field.embedFonts = true;
			
			var time_fmt:TextFormat = TmpModel.getTextFormat(60, 0xC7AE6C,true);
			time_fmt.letterSpacing = 2;
			time_field.defaultTextFormat = time_fmt;
			time_field.antiAliasType = AntiAliasType.ADVANCED;
			time_field.x = 0;
			time_field.y = 20;
			time_field.height = 70;
			time_field.width = 220;
			time_field.autoSize = TextFieldAutoSize.CENTER;
			addChild(time_field);
			date_field = new TextField();
			date_field.embedFonts = true;
			
			time_fmt.size = 22;
			time_fmt.color = 0x686868;
			date_field.defaultTextFormat = time_fmt;
			date_field.antiAliasType = AntiAliasType.ADVANCED;
			date_field.x = 0;
			date_field.y = 110;
			date_field.height = 35;
			date_field.width = 220;
			date_field.autoSize = TextFieldAutoSize.CENTER;
			addChild(date_field);
		}
		
		private function showDate():void {
			var dt:Date = new Date();
			time_field.text = dt.getHours() + ":" + ((dt.getMinutes()<10)?"0":"")+dt.getMinutes();
			date_field.text = dt.getDate() + " " + months[dt.getMonth()] + " " + dt.getFullYear();
		}
	}

}